import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Main {

	private JFrame frame;
	private JTextField d_start;
	private JTextField d_end;
	private JTextField summary;
	private JLabel lblGeographicPosition;
	private JTextField textField_6;
	private JLabel lblTimeZoneIdentifier;
	private JTextField txtHonoluluhi;
	private JTextField t_start;
	private JTextField t_end;
	private JComboBox priority;
	private JLabel lblNewLabel_1;
	private JLabel lblEx;
	private JComboBox classification;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main window = new Main();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Main() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 460);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Classification :");
		lblNewLabel.setBounds(33, 26, 124, 27);
		frame.getContentPane().add(lblNewLabel);
		
		JLabel lblTime = new JLabel("Priority : ");
		lblTime.setBounds(33, 108, 82, 27);
		frame.getContentPane().add(lblTime);
		
		JLabel lblTime_1 = new JLabel("Start Date and Time :");
		lblTime_1.setBounds(33, 151, 156, 27);
		frame.getContentPane().add(lblTime_1);
		
		JLabel lblTime_2 = new JLabel("End Date and Time :");
		lblTime_2.setBounds(33, 190, 156, 27);
		frame.getContentPane().add(lblTime_2);
		
		d_start = new JTextField();
		d_start.setColumns(10);
		d_start.setBounds(201, 151, 103, 28);
		frame.getContentPane().add(d_start);
		
		d_end = new JTextField();
		d_end.setColumns(10);
		d_end.setBounds(201, 190, 103, 28);
		frame.getContentPane().add(d_end);
		
		JLabel lblSummary = new JLabel("Summary : ");
		lblSummary.setBounds(33, 268, 156, 27);
		frame.getContentPane().add(lblSummary);
		
		summary = new JTextField();
		summary.setColumns(10);
		summary.setBounds(201, 267, 228, 28);
		frame.getContentPane().add(summary);
		
		lblGeographicPosition = new JLabel("Geographic Position :");
		lblGeographicPosition.setBounds(33, 65, 156, 27);
		frame.getContentPane().add(lblGeographicPosition);
		
		textField_6 = new JTextField();
		textField_6.setText("37.386013;-122.082932\n");
		textField_6.setEnabled(false);
		textField_6.setColumns(10);
		textField_6.setBounds(201, 66, 203, 28);
		frame.getContentPane().add(textField_6);
		
		lblTimeZoneIdentifier = new JLabel("Time\tzone\tidentifier :");
		lblTimeZoneIdentifier.setBounds(33, 229, 156, 27);
		frame.getContentPane().add(lblTimeZoneIdentifier);
		
		txtHonoluluhi = new JTextField();
		txtHonoluluhi.setText("honolulu,hi");
		txtHonoluluhi.setEnabled(false);
		txtHonoluluhi.setColumns(10);
		txtHonoluluhi.setBounds(201, 230, 103, 28);
		frame.getContentPane().add(txtHonoluluhi);
		
		JCheckBox chckbxRecurringEvents = new JCheckBox("Recurring Events");
		chckbxRecurringEvents.setBounds(136, 307, 143, 27);
		frame.getContentPane().add(chckbxRecurringEvents);
		
		classification = new JComboBox();
		classification.setModel(new DefaultComboBoxModel(new String[] {"Public", "Private", "Confidential"}));
		classification.setToolTipText("");
		classification.setBounds(201, 27, 134, 27);
		frame.getContentPane().add(classification);
		
		t_start = new JTextField();
		t_start.setColumns(10);
		t_start.setBounds(326, 150, 103, 28);
		frame.getContentPane().add(t_start);
		
		t_end = new JTextField();
		t_end.setColumns(10);
		t_end.setBounds(326, 189, 103, 28);
		frame.getContentPane().add(t_end);
		
		priority = new JComboBox();
		priority.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
		priority.setBounds(201, 109, 134, 27);
		frame.getContentPane().add(priority);
		
		lblNewLabel_1 = new JLabel("Ex: 07/13/2014");
		lblNewLabel_1.setBounds(201, 175, 103, 20);
		frame.getContentPane().add(lblNewLabel_1);
		
		lblEx = new JLabel("Ex: 15:24:31");
		lblEx.setBounds(336, 175, 103, 20);
		frame.getContentPane().add(lblEx);
		
		JButton btnNewButton = new JButton("Submit");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dt_start = d_start.getText().trim() + " " + t_start.getText().trim();
				String dt_end = d_end.getText().trim() + " " + t_end.getText().trim();
				System.out.println(Judgment.compareDate(dt_start, dt_end));
				String s = "";
				if (!Judgment.isDate(dt_start)) s = "The Start Date and Time is not valid\n";
				if (!Judgment.isDate(dt_end)) s += "The End Date and Time is not valid\n";
				if (summary.getText().equals("")) s += "The summary can't be empty\n";
				if (!s.equals("")) {
					JOptionPane.showMessageDialog(null,
							s,
							"ERROR",
							JOptionPane.ERROR_MESSAGE); 
					return;
				}
				if (Judgment.compareDate(dt_start, dt_end) > 0 ) s +="The Start date cannot greater than End date";
				if (!s.equals("")) {
					JOptionPane.showMessageDialog(null,
							s,
							"ERROR",
							JOptionPane.ERROR_MESSAGE); 
					return;
				}
				Producer.init(String.valueOf(classification.getSelectedItem()), 
						String.valueOf(priority.getSelectedItem()),
						Judgment.convertDateAndTime(d_start.getText().trim() , t_start.getText().trim()), 
						Judgment.convertDateAndTime(d_end.getText().trim() , t_end.getText().trim()), 
						summary.getText());
			}
		});
		btnNewButton.setBounds(147, 368, 117, 29);
		frame.getContentPane().add(btnNewButton);

	}
}
